{%- set this_id       = salt['grains.get']('id') %}
{%- set this_hostname = salt['grains.get']('localhost', '') %}
{%- set this_roles    = salt['grains.get']('roles', []) %}

{%- macro nodes_entries_from_mine(expr) -%}
{% for server, addr in salt['mine.get'](expr, 'network.ip_addrs', tgt_type='compound').items() -%}
{{ addr[0] }} {{ server }} {{ server }}.{{ pillar['internal_infra_domain'] }}
{% endfor %}
{%- endmacro %}


{##################################################################}
### salt nodes ###
{{ nodes_entries_from_mine('G@roles:salt') }}

### frontend-gateway ###
{{ nodes_entries_from_mine('G@roles:frontend-gateway') }}

### elasticsearch ###
{{ nodes_entries_from_mine('G@roles:elasticsearch') }}

### kibana ###
{{ nodes_entries_from_mine('G@roles:kibana') }}

### go-server ###
{{ nodes_entries_from_mine('G@roles:gocd') }}

### go-agent ###
{{ nodes_entries_from_mine('G@roles:go-agent') }}

### internet-gateway ###
{{ nodes_entries_from_mine('G@roles:internet-gateway') }}

### intranet-gateway ###
{{ nodes_entries_from_mine('G@roles:intranet-gateway') }}

### nexus ###
{{ nodes_entries_from_mine('G@roles:nexus') }}

### mongodb ###
{{ nodes_entries_from_mine('G@roles:mongodb') }}

### kubernetes masters ###
{{ nodes_entries_from_mine('G@roles:kube-master') }}

### kubernetes workers ###
{{ nodes_entries_from_mine('G@roles:kube-minion') }}

### other machines in the env (ie, unassigned machines...) ###
{{ nodes_entries_from_mine('not ( P@roles:(salt|ca|frontend-gateway|internet-gateway|elasticsearch|kibana|gocd|go-agent|intranet-gateway|nexus|mongodb) or P@roles:kube-(master|minion) )') }}

{%- if 'intranet-gateway' in salt['grains.get']('roles', []) %}
### services in ADCC ###
{%- for integration in pillar.get('integration_services', {}).values() %}
{%- if integration.ip is defined %}
{{'%-15s\t%s' | format(integration.ip, integration.address.rpartition("//")[-1])}}
{%- endif %}
{%- endfor %}
{%- endif %}
